package com.youpai.platform.chat.service.service;

import com.alibaba.fastjson.JSONObject;
import com.youpai.platform.chat.service.entity.dto.AckMsgDTO;
import com.youpai.platform.vulture.common.enums.ServerCommandEnum;
import com.youpai.platform.vulture.service.entity.dto.SendMessageDTO;
import com.youpai.platform.vulture.service.router.MessageRouterService;

/**
 * @time: 2022/8/3 8:08 下午
 * @author: welles
 * @description: 消息应答接口
 */
public abstract class AckMsgService {

    /**
     * 应答的消息
     *
     * @param ackMsgDTO 应答消息
     */
    protected void ackMsg(MessageRouterService messageRouterService, AckMsgDTO ackMsgDTO, String toAccId) {
        SendMessageDTO sendMessageDTO = buildSendMessageDTO(ackMsgDTO, toAccId);
        messageRouterService.sendMessage(sendMessageDTO);
    }

    protected SendMessageDTO buildSendMessageDTO(AckMsgDTO ackMsgDTO, String toAccId) {
        SendMessageDTO sendMessageDTO = new SendMessageDTO();
        sendMessageDTO.setCmd(ServerCommandEnum.ACK_MESSAGE.cmd)
                .setToAccId(toAccId)
                .setBody(JSONObject.toJSONString(ackMsgDTO));
        return sendMessageDTO;
    }
}
